package com.cskaoyan.service.impl;

import com.cskaoyan.bean.chenfeng.vo.StatGoodsVo;
import com.cskaoyan.bean.chenfeng.vo.StatOrderVo;
import com.cskaoyan.bean.chenfeng.vo.StatUserVo;
import com.cskaoyan.mapper.MarketOrderGoodsMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Chen_Feng
 * @since 2022/06/28 23:46
 */
@Service
@Transactional
public class StatServiceImpl implements StatService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    MarketOrderMapper orderMapper;

    @Autowired
    MarketOrderGoodsMapper marketOrderGoodsMapper;

    /**
     * 统计新增的用户数据
     *
     * @return com.cskaoyan.bean.chenfeng.vo.StatUserVo
     * @author Chen_Feng
     * @since 2022/06/28 23:46
     */
    @Override
    public StatUserVo getUserStatData() {

        // 查询数据
        List<StatUserVo.RowsEntity> rows = userMapper.selectUserInGroupByDate("add_time", "asc", 7);

        // 封装数据
        StatUserVo statUserVo = new StatUserVo();
        statUserVo.setRows(rows);

        return statUserVo;
    }

    /**
     * 查询订单统计数据
     *
     * @return com.cskaoyan.bean.chenfeng.vo.StatUserVo
     * @author Chen_Feng
     * @since 2022/06/29 0:56
     */
    @Override
    public StatOrderVo getOrderStatData() {

        // 查询数据
        List<StatOrderVo.RowsEntity> rows = orderMapper.selectOrderInGroupByDate("add_time", "asc", 5);

        // 封装数据
        StatOrderVo statOrderVo = new StatOrderVo();
        statOrderVo.setRows(rows);

        return statOrderVo;
    }

    /**
     * 查询商品统计数据
     *
     * @return com.cskaoyan.bean.chenfeng.vo.StatGoodsVo
     * @author Chen_Feng
     * @since 2022/06/29 2:02
     */
    @Override
    public StatGoodsVo getGoodsStatData() {

        // 查询数据
        List<StatGoodsVo.RowsEntity> rows = marketOrderGoodsMapper.selectGoodsInGroupByDate("add_time", "asc", 5);

        // 封装数据
        StatGoodsVo statGoodsVo = new StatGoodsVo();
        statGoodsVo.setRows(rows);

        return statGoodsVo;
    }
}
